from django_filters import rest_framework

from apps.envs.models import Env, Service, EnvService, Plant, EnvPlant, Module, Page, Headers, EnvGlobalParams


class EnvFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Env
        fields = '__all__'


class EnvGlobalParamsFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')
    remark = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = EnvGlobalParams
        fields = '__all__'


class ServiceFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Service
        fields = '__all__'


class HeadersFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Headers
        fields = ['name', 'project']


class EnvServiceFilter(rest_framework.FilterSet):
    host = rest_framework.CharFilter(lookup_expr='contains')
    project = rest_framework.CharFilter(field_name='env__project')

    class Meta:
        model = EnvService
        fields = '__all__'


class PlantFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Plant
        fields = '__all__'


class EnvPlantFilter(rest_framework.FilterSet):
    host = rest_framework.CharFilter(lookup_expr='contains')
    project = rest_framework.CharFilter(field_name='env__project')

    class Meta:
        model = EnvPlant
        fields = '__all__'


class ModuleFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Module
        fields = '__all__'


class PageFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')
    module = rest_framework.BaseInFilter(lookup_expr='in')

    class Meta:
        model = Page
        fields = '__all__'
